{template '../web_common/header'}

<!-- 中间内容 -->
<div class="mainContent clearfix">
    <div class="center-con clearfix">
        <h2 class="main-ttl">编辑信息</h2>
        <div class="main-ctn clearfix">
            <div class="item clearfix">
                <div class="l">
                    <span>员工ID：</span>
                </div>
                <div class="r">
                    <input type="text" class="input-text" readonly="readonly" value="{$item['employee_id']}" style="border:none;outline: none">
                </div>
            </div>
            <div class="item clearfix">
                <div class="l">
                    <span>微信昵称：</span>
                </div>
                <div class="r">
                    <input type="text" class="input-text" readonly="readonly" value="{$item['nickname']}" style="border:none;outline: none">
                </div>
            </div>
            <div class="item clearfix">
                <div class="l">
                    <span>姓名：</span>
                </div>
                <div class="r">
                    <input type="text" class="input-text" value="{$item['employee_name']}" name="employee_name">
                </div>
            </div>
            <div class="item clearfix">
                <div class="l">
                    <span>手机号：</span>
                </div>
                <div class="r">
                    <input type="text" class="input-text" value="{$item['mobile']}" maxlength="11" name="mobile">
                </div>
                <div class="r">
                    <span class="mobile_tip" style="color: #ff0000;display: none">&nbsp; * 请输入正确的手机号</span>
                </div>
            </div>
            <div class="item clearfix" style="margin-bottom: 80px;">
                <div class="l">
                    <span>备注：</span>
                </div>
                <div class="r">
                    <textarea id="remarks" rows="5" name="remarks" placeholder="50字以内">{$item['remarks']}</textarea>
                    <span id="num_str" style="color: #ff0000;display: none;text-align: right">已超50字</span>
                </div>
            </div>
            <div class="item clearfix mt20" style="position: absolute; left: 20px;bottom: 20px;">
                <button type="submit" class="Btn" id="submit">提交</button>
                <button type="button" class="Btn ml10" id="return" onclick="window.location.href='{php echo $this->createWebUrl('employee', array('act' => 'index'));}'">返回/取消</button>
            </div>
        </div>
    </div>
</div>
<!-- 底部内容 -->
<script>
    require(['jquery', 'layer', 'common'], function ($) {
        $('input[name=mobile]').keyup(function(){
            check_mobile($(this).val());
        });

        isLock = false;//是否锁定当前的输入状态  
        document.querySelector('#remarks').addEventListener('input',function(){
            //只有在非中文输入状态的时候，才能更改数字  
            if(!isLock){
                var num = this.value.length;
                if (num > 50) {
                    $('#num_str').css('display', 'block');
                    $('#submit').attr('disabled', 'disabled');
                    return false;
                } else {
                    $('#num_str').css('display', 'none');
                    $('#submit').removeAttr('disabled');
                }
            }
        });

        $('#submit').on('click',function(){
            var employee_name=$('input[name=employee_name]').val();
            var mobile=$('input[name=mobile]').val();
            var remarks=$('#remarks').val();
            if (mobile.length != 0) {
                if (check_mobile(mobile) == 0) {
                    layer.msg('请输入正确的手机号');
                    return false;
                }
            }

            var data = {
                employee_name: employee_name,
                mobile: mobile,
                remarks: remarks,
                token: "{$_W['token']}",
                submit: 'submit'
            };

            $.post("{php echo $this->createWebUrl('employee', array('act' => 'edit','employee_id' => $item['employee_id']))}", data, function (data) {
                if(data.code === 200){
                    layer.msg(data.msg, {icon: 1,time:1000});
                }else{
                    layer.msg(data.msg, {icon: 2,time:1000});
                    return false;
                }
            });
        })
    });

    function check_mobile(mobile) {
        var myreg = /^(((13[0-9]{1})|(15[0-9]{1})|(18[0-9]{1}))+\d{8})$/;
        if(!myreg.test(mobile)) {
            $('.mobile_tip').css('display', 'block');
            return 0;
        } else {
            $('.mobile_tip').css('display', 'none');
            return 1;
        }
    }

</script>

{template '../web_common/footer'}